﻿
@using Sharp.Web.Models
@model Sharp.Web.Models.IndexModel
@{
    ViewBag.Title = "后台首页";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";
    var x = Html.X();
}
@section headtag{
    <link rel="stylesheet" href="@Url.Content("~/Content/resources/css/main.css")" />
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/Bundles/Manage")
    
    <script>
        Ext.onReady(function () {
            Ext.ns("App.direct");
            Ext.apply(App.direct,
            {
                GetThemeUrl: function (theme, reload, config) {
                    return Ext.net.DirectMethod.request("GetThemeUrl", Ext.applyIf(config || {},
                    {
                        params: {
                            theme: theme,
                            reload: reload
                        },
                        url: "/Main/GetThemeUrl"
                    }));
                },
                GetHashCode: function (name, config) {
                    return Ext.net.DirectMethod.request("GetHashCode", Ext.applyIf(config || {},
                    {
                        params: {
                            name: name
                        },
                        url: "/Main/GetHashCode"
                    }));
                },
                GetFormPanel: function (id, url, config) {
                    return Ext.net.DirectMethod.request("GetFormPanel", Ext.applyIf(config || {},
                    {
                        params: {
                            id: id,
                            url: url
                        },
                        url: "/Main/GetFormPanel"
                    }));
                }
            });
        });
        function Logout() {
            Ext.MessageBox.confirm('询问', '您是否要退出系统？',
                  function (btn, text) {
                      if (btn == 'yes') {
                          $.get("/Account/Logout", function (data, textStatus) {
                              window.location = "/Login";
                          });

                      }
                  });
        }
    </script>
}
@{
    Theme theme = Ext.Net.Theme.Neptune;

    if (Session["Ext.Net.Theme"] != null)
    {
        theme = (Theme)Session["Ext.Net.Theme"];
    }

    List<CheckMenuItem> themeItems = new List<CheckMenuItem>()
    {
        new CheckMenuItem
        {
            Text = "Default",
            Group = "theme"
        },
        new CheckMenuItem
        {
            Text = "Blue",
            Group = "theme"
        },
        new CheckMenuItem
        {
            Text = "Crisp",
            Group = "theme"
        },
        new CheckMenuItem
        {
            Text = "Neptune",
            Group = "theme"
        },
        new CheckMenuItem
        {
            Text = "Neptune Touch",
            Group = "theme"
        }
    };

    string themeName = theme.ToString();

    themeItems.First(item => item.Text == themeName).Checked = true;

    ResourceManager.RegisterControlResources<TagLabel>();
    Html.X().History().Listeners(l => l.Change.Fn = "App.Main.change");
}
 
@section example
{
    @(x.Viewport()
          .Layout(LayoutType.Border)
          .Items(
              x.Panel()
                  .Region(Region.North)
                  .Split(false)
                  .Collapsible(false)
                  .TopBar(Html.X().Toolbar().Items(items =>
                  {

                      items.Add(new ToolbarTextItem { Text = "欢迎您：" });
                      items.Add(new Hyperlink { Text = Model.UserName });
                      items.Add(new ToolbarSpacer());
                      items.Add(new ToolbarSeparator());
                      items.Add(new ToolbarSpacer());


                      items.Add(new Hyperlink { Text = "首页", NavigateUrl = "/Main/" });

                      items.Add(new ToolbarSpacer());
                      items.Add(new ToolbarSeparator());
                      items.Add(new ToolbarSpacer());

                      items.Add(new Hyperlink { Text = "资料" });

                      items.Add(new ToolbarSpacer());
                      items.Add(new ToolbarSeparator());
                      items.Add(new ToolbarSpacer());

                      items.Add(new Hyperlink { Text = string.Format("消息 ({0})", Model.NewMessageCount) });

                      items.Add(new ToolbarSpacer());
                      items.Add(new ToolbarSeparator());
                      items.Add(new ToolbarSpacer());

                      items.Add(new Hyperlink { Text = "帮助" });

                      items.Add(new ToolbarFill());

                      items.Add(new Button
                      {
                          Text = "账号",
                          Menu =
                          {
                              new Menu
                              {
                                  Items =
                                  {
                                      new MenuItem
                                      {
                                          Text = "注销登录", Icon = Icon.DoorOut, OnClientClick="Logout()"},
                                      new MenuItem {Text = "关于", Icon = Icon.Information, DirectClickAction="About"}
                                  }
                              }
                          }
                      });
                      items.Add(new Button()
                      {
                          Text = "设置",
                          Icon = Icon.Cog,
                          DirectClickAction = "Custom"
                      });


                  })),
              x.Panel()
                  .Title("功能面板")
                  .Region(Region.West)
                  .Layout(LayoutType.Fit)
                  .Width(225)
                  .MinWidth(225)
                  .MaxWidth(400)
                  .Split(true)
                  .Collapsible(true)
                  .CollapseMode(CollapseMode.Mini)
                  .Items(x.TreePanel().ID("exampleTree")
                      .TopBar(
                          new Toolbar
                          {
                              Items =
                              {
                                  new TextField
                                  {
                                      ID = "SearchField",
                                      AutoFocus = true,
                                      EnableKeyEvents = true,
                                      Flex = 1,
                                      Triggers =
                                      {
                                          new FieldTrigger
                                          {
                                              //HideTrigger = true,
                                              Icon = TriggerIcon.Clear
                                          }
                                      },
                                      Listeners =
                                      {
                                          KeyUp =
                                          {
                                              Buffer = 100,
                                              Fn = "App.Main.keyUp"
                                          },
                                          TriggerClick =
                                          {
                                              Fn = "App.Main.clearFilter"
                                          },
                                          SpecialKey =
                                          {
                                              Fn = "App.Main.filterSpecialKey",
                                              Delay = 1
                                          }
                                      }
                                  },
                                  new Button
                                  {
                                      Icon = Icon.Cog,
                                      ToolTip = "选项",
                                      Menu =
                                      {
                                          new Menu
                                          {
                                              Items =
                                              {
                                                  new MenuItem
                                                  {
                                                      Text = "全部展开",
                                                      IconCls = "icon-expand-all",
                                                      Handler = "this.up('treepanel').expandAll(false);"
                                                  },
                                                  new MenuItem
                                                  {
                                                      Text = "全部折叠",
                                                      IconCls = "icon-collapse-all",
                                                      Handler = "this.up('treepanel').collapseAll(false);"
                                                  },
                                                  new MenuSeparator(),
                                                  new MenuItem
                                                  {
                                                      Text = "主题",
                                                      Icon = Icon.Paintcan,
                                                      Menu =
                                                      {
                                                          new Menu
                                                          {
                                                              Items =
                                                              {
                                                                  themeItems
                                                              },
                                                              Listeners =
                                                              {
                                                                  Click =
                                                                  {
                                                                      Fn = "App.Main.themeChange"
                                                                  }
                                                              }
                                                          }
                                                      }
                                                  },
                                                  new MenuSeparator(),
                                                  x.MenuItem().Text("搜索选项").Icon(Icon.Find).Menu(x.Menu().Items(
                                                      x.CheckMenuItem().ID("SearchByTitles").Checked(true).Text("Titles"),
                                                      x.CheckMenuItem().ID("SearchByTags").Checked(true).Text("Tags")
                                                      ))
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                      )
                      .Border(false).AutoScroll(true).Lines(true)
                      .RootVisible(false).HideHeaders(true).Animate(false).Root(Model.LeftTree)
                      .ColumnModel(
                          new TreeColumn()
                          {
                              DataIndex = "text",
                              Flex = 1,
                              Renderer =
                              {
                                  Fn = "App.Main.treeRenderer"
                              }
                          })
                      .Listeners(li =>
                      {
                          li.ItemClick.Handler = "App.Main.onTreeItemClick(record, e);";
                          li.AfterRender.Fn = "App.Main.onTreeAfterRender";
                      })),
              x.TabPanel()
                  .ID("ExampleTabs")
                  .Region(Region.Center)
                  .MinTabWidth(110)
                  .Items(items => items.Add(new Panel
                  {
                      Title = "桌面",
                      HideMode = HideMode.Offsets,
                      Icon = Icon.Application,
                      Layout = "fit",
                      Items =
                      {
                          x.Portal().Items(
                            x.PortalColumn().ColumnWidth(.5).Items(x.Portlet().Title("消息").Height(300).Items(    
                                x.GridPanel()
                                .Store(x.StoreFor( typeof(MessageIndexModel) )
                                .Proxy(x.AjaxProxy().Url(Url.Action("GetPaged","Message")).Reader(x.JsonReader().RootProperty("data")))
                                .RemoteSort(true).RemotePaging(true).PageSize(25).Sorters("Id", Ext.Net.SortDirection.DESC))
                                .SelectionModel(x.CheckboxSelectionModel())
                                .ColumnModel(
                                x.Column().DataIndex("Title").Text("标题").Width(200),
                                x.DateColumn().DataIndex("PublishTime").Text("发布时间").Width(200).Format("yyyy-MM-dd")
                                )
                                .EmptyText("无数据。")
                                .View(x.GridView().StripeRows(true).TrackOver(true)))),
                            x.PortalColumn().ColumnWidth(.5))
                      }
                  }))

                    .Listeners(l => { l.TabChange.Fn = "App.Main.addToken"; })
                  .Plugins(plugins => plugins.Add(new TabCloseMenu()))
          )
          )

}